﻿namespace Admin_Commands
{
    using CommandHandler;
    using Ini;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using System.Threading;
    using System.Timers;
    using UnityEngine;

    public class AdminCommands : MonoBehaviour
    {
        public int announceIndex = 0;
        public int announceIntervalInSeconds = 600;
        public string[] AnnounceMessages;
        public System.Timers.Timer announceTimer;
        public string bigAssStringWithBannedPlayerNamesAndSteamIDs = "";
        private Dictionary<string, Vector3> frozenPlayers = new Dictionary<string, Vector3>();
        public int itemsResetIntervalInSeconds = 0xa8c;
        public System.Timers.Timer itemsTimer;
        public string lastUsedCommand = "none";
        private Dictionary<string, Vector3> playerHomes = new Dictionary<string, Vector3>();
        private static System.Random random = new System.Random((int)DateTime.Now.Ticks);
        public bool respawnVehicles = false;
        public bool showWhiteListKickMessages = true;
        private int updater3 = 0;
        public bool usePlayerHomes = false;
        private BetterNetworkUser userToBeBanned;
        public bool usingGUI = true;
        public bool usingWhitelist = false;
        private Dictionary<string, Vector3> vanishedPlayers = new Dictionary<string, Vector3>();
        public List<string> WhitelistedSteamIDs = new List<string>();

        private void Announce(CommandArgs args)
        {
            NetworkChat.sendAlert(args.ParametersAsString);
        }

        private void announceNext()
        {
            for (int i = this.announceIndex; i < this.AnnounceMessages.Length; i++)
            {
                string str = this.AnnounceMessages[i];
                if (str.Equals(":"))
                {
                    this.announceIndex = i + 1;
                    return;
                }
                NetworkChat.sendAlert(str);
            }
            this.announceIndex = 0;
        }

        public void announcesTimeElapsed(object sender, ElapsedEventArgs e)
        {
            this.announceNext();
        }

        private void Ban(CommandArgs args)
        {
            string parametersAsString = args.ParametersAsString;
            int result = 0;
            if ((parametersAsString.Length < 3) && int.TryParse(base.name, out result))
            {
                this.userToBeBanned = UserList.users[result];
                string name = this.userToBeBanned.name;
                Reference.Tell(args.sender.networkPlayer, "玩家" + name + "被BAN原因? /reason <原因>");
            }
            else
            {
                this.userToBeBanned = UserList.getUserFromName(parametersAsString);
                Reference.Tell(args.sender.networkPlayer, "玩家" + this.userToBeBanned.name + "被BAN原因? /reason <原因>");
            }
        }

        private void Ban(BetterNetworkUser userToBeBanned, string reason)
        {
            NetworkTools.ban(userToBeBanned.networkPlayer, userToBeBanned.name, userToBeBanned.steamid, reason);
        }

        private void DisableWhitelist(CommandArgs args)
        {
            this.usingWhitelist = false;
            NetworkChat.sendAlert("已禁用白名单。");
        }

        private void EnableWhitelist(CommandArgs args)
        {
            this.usingWhitelist = true;
            NetworkChat.sendAlert("已启用白名单。");
        }

        private void FreezePlayer(CommandArgs args)
        {
            BetterNetworkUser user = UserList.getUserFromName(args.ParametersAsString);
            if (user != null)
            {
                Player player = user.player;
                this.frozenPlayers.Add(user.steamid, player.transform.position);
            }
            Reference.Tell(args.sender.networkPlayer, "封冻玩家<" + user.name + ">");
        }

        private void GodMode(CommandArgs args)
        {
            Life component = args.sender.player.gameObject.GetComponent<Life>();
            if (((args.Parameters != null) && (args.Parameters.Count > 0)) && args.ParametersAsString.ToLower().Equals("off"))
            {
                component.networkView.RPC("tellAllLife", RPCMode.All, new object[] { 100, 100, 100, 100, false, false });
                component.damage(1, "poke");
            }
            else
            {
                component.networkView.RPC("tellAllLife", RPCMode.All, new object[] { 0x2710, 100, 100, 100, false, false });
                component.damage(1, "poke");
            }
        }

        private void Heal(CommandArgs args)
        {
            if (args.Parameters.Count == 0)
            {
                args.sender.player.gameObject.GetComponent<Life>().heal(100, true, true);
            }
            else
            {
                UserList.getUserFromName(args.ParametersAsString).player.gameObject.GetComponent<Life>().heal(100, true, true);
            }
        }

        private void home(BetterNetworkUser user)
        {
            this.teleportUserTo(user, this.playerHomes[user.steamid]);
        }

        private void Home(CommandArgs args)
        {
            if (this.usePlayerHomes)
            {
                this.home(args.sender);
                Reference.Tell(args.sender.networkPlayer, "已传送到家，为避免被误检为外挂而被踢，请在5秒钟内不要移动。");
            }
        }

        private void itemsTimeElapsed(object sender, ElapsedEventArgs e)
        {
            this.resetItems();
        }

        private void Kick(CommandArgs args)
        {
            string parametersAsString = args.ParametersAsString;
            this.Kick(parametersAsString, "你已被踢出服务器");
        }

        private void Kick(string name, string reason)
        {
            NetworkTools.kick(UserList.getUserFromName(name).networkPlayer, reason);
        }

        private void kickNonWhitelistedPlayers()
        {
            if (this.usingWhitelist && (this.updater3 <= 1))
            {
                foreach (BetterNetworkUser user in UserList.users)
                {
                    if ((user.networkPlayer != Network.player) && !this.WhitelistedSteamIDs.Contains(user.steamid))
                    {
                        if (this.showWhiteListKickMessages)
                        {
                            this.Kick(user.name, "本服定期开启白名单,您现在不在白名单内,请入群看群公告384078192！");
                        }
                        else
                        {
                            NetworkChat.sendNotification(user.networkPlayer, "本服定期开启白名单,您现在不在白名单内,请入群看群公告384078192！");
                            Network.CloseConnection(user.networkPlayer, true);
                        }
                    }
                }
                this.updater3 = 100;
            }
            this.updater3--;
        }

        private void Kill(CommandArgs args)
        {
            UserList.getUserFromName(args.ParametersAsString).player.gameObject.GetComponent<Life>().damage(500, "你被管理员击杀！");
        }

        private void Killzombies(CommandArgs args)
        {
            Zombie[] zombieArray = UnityEngine.Object.FindObjectsOfType(typeof(Zombie)) as Zombie[];
            foreach (Zombie zombie in zombieArray)
            {
                zombie.damage(500);
            }
            NetworkChat.sendAlert(string.Concat(new object[] { zombieArray.Length, "个僵尸已被", args.sender.name, "击杀" }));
        }

        private void lag(CommandArgs args)
        {
            BetterNetworkUser user = UserList.getUserFromName(args.ParametersAsString);
            Network.SetReceivingEnabled(user.networkPlayer, 0, false);
            Reference.Tell(args.sender.networkPlayer, "你已" + user.name + "人为LAG");
        }

        public void loadBans()
        {
            this.bigAssStringWithBannedPlayerNamesAndSteamIDs = PlayerPrefs.GetString("bans");
        }

        private void Log(string p)
        {
            StreamWriter writer = new StreamWriter("Unturned_Data/Managed/mods/AdminCommands_Log.txt", true);
            writer.WriteLine(p);
            writer.Close();
        }

        private void MaxSkills(CommandArgs args)
        {
            args.sender.player.GetComponent<Skills>().learn(0x2710);
        }

        public void OnGUI()
        {
            if (this.usingGUI)
            {
                GUI.BeginGroup(new Rect(50f, 100f, 600f, 70f));
                GUI.Box(new Rect(0f, 0f, 530f, 400f), "Admin Commands v2 已在运行！上次使用命令：" + CommandList.lastUsedCommand);
                GUI.EndGroup();
            }
        }

        private void Online(CommandArgs args)
        {
            Reference.Tell(args.sender.networkPlayer, "服务器现在有" + UserList.NetworkUsers.Count + "个玩家在线。");
        }

        private void Promote(CommandArgs args)
        {
            string parametersAsString = args.ParametersAsString;
            BetterNetworkUser user = UserList.getUserFromName(parametersAsString);
            UserList.promote(user.steamid);
            Reference.Tell(args.sender.networkPlayer, parametersAsString + "已被提升至级别：" + UserList.getPermission(user.steamid));
            Reference.Tell(user.networkPlayer, "你已被提升至级别：" + UserList.getPermission(user.steamid));
        }

        private string RandomString(int size)
        {
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < size; i++)
            {
                char ch = Convert.ToChar(Convert.ToInt32(Math.Floor((double)((26.0 * random.NextDouble()) + 65.0))));
                builder.Append(ch);
            }
            return builder.ToString();
        }

        private void ReadConfigs()
        {
            StreamWriter writer;
            int num;
            Directory.CreateDirectory("Unturned_Data/Managed/mods/AdminCommands");
            if (!File.Exists("Unturned_Data/Managed/mods/AdminCommands/config.ini"))
            {
                IniFile file = new IniFile("Unturned_Data/Managed/mods/AdminCommands/config.ini");
                file.IniWriteValue("Config", "Using Whitelist", "false");
                file.IniWriteValue("Config", "Using Player Homes", "false");
                file.IniWriteValue("Config", "Show gui", "true");
                file.IniWriteValue("Config", "Show whitelist kick messages", "true");
                file.IniWriteValue("Security", "Using_console", "true");
                file.IniWriteValue("Security", "Console_password", this.RandomString(8));
                file.IniWriteValue("Security", "Require_command_confirmation", "false");
                file.IniWriteValue("Timers", "Time between item respawns in seconds", "2700");
                file.IniWriteValue("Timers", "Time between announces in seconds", "600");
            }
            IniFile file2 = new IniFile("Unturned_Data/Managed/mods/AdminCommands/config.ini");
            if (file2.IniReadValue("Config", "Show whitelist kick messages").Equals(""))
            {
                file2.IniWriteValue("Config", "Show whitelist kick messages", "true");
            }
            if (file2.IniReadValue("Security", "Using_console").Equals(""))
            {
                file2.IniWriteValue("Security", "Using_console", "true");
            }
            if (file2.IniReadValue("Security", "Console_password").Equals(""))
            {
                file2.IniWriteValue("Security", "Console_password", this.RandomString(8));
            }
            if (file2.IniReadValue("Security", "Require_command_confirmation").Equals(""))
            {
                file2.IniWriteValue("Security", "Require_command_confirmation", "false");
            }
            this.usingWhitelist = bool.Parse(file2.IniReadValue("Config", "Using Whitelist"));
            this.usingGUI = bool.Parse(file2.IniReadValue("Config", "Show gui"));
            this.usePlayerHomes = bool.Parse(file2.IniReadValue("Config", "Using Player Homes"));
            this.showWhiteListKickMessages = bool.Parse(file2.IniReadValue("Config", "Show whitelist kick messages"));
            this.itemsResetIntervalInSeconds = int.Parse(file2.IniReadValue("Timers", "Time between item respawns in seconds"));
            this.announceIntervalInSeconds = int.Parse(file2.IniReadValue("Timers", "Time between announces in seconds"));
            if (!File.Exists("Unturned_Data/Managed/mods/AdminCommands/UnturnedWhitelist.txt"))
            {
                writer = new StreamWriter("Unturned_Data/Managed/mods/AdminCommands/UnturnedWhitelist.txt", true);
                writer.WriteLine("76561197976976379");
                writer.Close();
            }
            string[] strArray = File.ReadAllLines("Unturned_Data/Managed/mods/AdminCommands/UnturnedWhitelist.txt");
            for (num = 0; num < strArray.Length; num++)
            {
                if (strArray[num].Length > 10)
                {
                    this.WhitelistedSteamIDs.Add(strArray[num]);
                }
            }
            if (!File.Exists("Unturned_Data/Managed/mods/AdminCommands/playerHomes.txt"))
            {
                writer = new StreamWriter("Unturned_Data/Managed/mods/AdminCommands/playerHomes.txt", true);
                writer.WriteLine("");
                writer.Close();
            }
            string[] strArray2 = File.ReadAllLines("Unturned_Data/Managed/mods/AdminCommands/playerHomes.txt");
            for (num = 0; num < strArray2.Length; num++)
            {
                if (strArray2[num].Length > 5)
                {
                    string str = strArray2[num].Split(new char[] { ':' })[0];
                    string str2 = strArray2[num].Split(new char[] { ':' })[1];
                    string str3 = str2.Split(new char[] { ',' })[0];
                    string str4 = str2.Split(new char[] { ',' })[1];
                    string str5 = str2.Split(new char[] { ',' })[2];
                    Vector3 vector = new Vector3(Convert.ToSingle(str3), Convert.ToSingle(str4), Convert.ToSingle(str5));
                    this.playerHomes[str] = vector;
                }
            }
            if (!File.Exists("Unturned_Data/Managed/mods/AdminCommands/UnturnedAnnounces.txt"))
            {
                writer = new StreamWriter("Unturned_Data/Managed/mods/AdminCommands/UnturnedAnnounces.txt", true);
                writer.WriteLine("This line will be announced 10 minutes after injecting (or whatever you change the interval to)");
                writer.WriteLine("This line will be announced at the same time");
                writer.WriteLine(":");
                writer.WriteLine("This line will be announced 20 minutes after injecting  (2x interval)");
                writer.WriteLine(":");
                writer.WriteLine(":");
                writer.WriteLine("This line will be announced 40 minutes after injecting  (4x interval)");
                writer.WriteLine("And so forth.. then it will go back to the 1st line      (4x interval)");
                writer.Close();
            }
            string[] strArray3 = File.ReadAllLines("Unturned_Data/Managed/mods/AdminCommands/UnturnedAnnounces.txt");
            this.AnnounceMessages = new string[strArray3.Length];
            for (num = 0; num < strArray3.Length; num++)
            {
                this.AnnounceMessages[num] = strArray3[num];
            }
            this.itemsTimer = new System.Timers.Timer((double)(this.itemsResetIntervalInSeconds * 0x3e8));
            this.itemsTimer.Elapsed += new ElapsedEventHandler(this.itemsTimeElapsed);
            this.itemsTimer.Enabled = true;
            this.announceTimer = new System.Timers.Timer((double)(this.announceIntervalInSeconds * 0x3e8));
            this.announceTimer.Elapsed += new ElapsedEventHandler(this.announcesTimeElapsed);
            this.announceTimer.Enabled = true;
        }

        private void ReasonForBan(CommandArgs args)
        {
            string parametersAsString = args.ParametersAsString;
            if (args.Parameters.Count > 0)
            {
                this.Ban(this.userToBeBanned, parametersAsString);
            }
        }

        private void RefuelVehicles(CommandArgs args)
        {
            Vehicle[] vehicleArray = UnityEngine.Object.FindObjectsOfType(typeof(Vehicle)) as Vehicle[];
            foreach (Vehicle vehicle in vehicleArray)
            {
                vehicle.fill(0x3e8);
            }
            NetworkChat.sendAlert(string.Concat(new object[] { args.sender.name, " 已刷新", vehicleArray.Length, "辆车" }));
        }

        private void ReloadBans(CommandArgs args)
        {
            NetworkBans.load();
        }

        private void RepairVehicles(CommandArgs args)
        {
            Vehicle[] vehicleArray = UnityEngine.Object.FindObjectsOfType(typeof(Vehicle)) as Vehicle[];
            foreach (Vehicle vehicle in vehicleArray)
            {
                vehicle.networkView.RPC("tellExploded", RPCMode.All, new object[] { false });
                vehicle.networkView.RPC("tellWrecked", RPCMode.All, new object[] { false });
                vehicle.heal(0x3e8);
            }
            NetworkChat.sendAlert(string.Concat(new object[] { args.sender.name, " 已维修", vehicleArray.Length, "辆车" }));
        }

        public void resetItems()
        {
            SpawnItems.reset();
        }

        private void ResetItems(CommandArgs args)
        {
            SpawnItems.reset();
            NetworkChat.sendAlert("<" + args.sender.name + ">已刷新所有物品");
        }

        private void ResetZombies(CommandArgs args)
        {
            SpawnAnimals.reset();
            NetworkChat.sendAlert("<" + args.sender.name + ">已重生所有僵尸");
        }

        private void RespawnVehicles(CommandArgs args)
        {
            GameObject obj2 = (GameObject)typeof(SpawnVehicles).GetFields()[0].GetValue(null);
            try
            {
                Vehicle[] vehicleArray = UnityEngine.Object.FindObjectsOfType(typeof(Vehicle)) as Vehicle[];
                foreach (Vehicle vehicle in vehicleArray)
                {
                    vehicle.networkView.RPC("tellExploded", RPCMode.All, new object[] { true });
                    vehicle.networkView.RPC("tellWrecked", RPCMode.All, new object[] { true });
                }
                int childCount = obj2.transform.FindChild("models").childCount;
                for (int i = 0; i < childCount; i++)
                {
                    Transform child = obj2.transform.FindChild("models").GetChild(i);
                    Network.RemoveRPCs(child.networkView.viewID);
                    Network.Destroy(child.networkView.viewID);
                }
            }
            catch
            {
            }
            SpawnVehicles.save();
            Reference.Tell(args.sender.networkPlayer, "3秒内即将刷新" + Loot.getCars() + "辆车");
            System.Threading.Timer timer = new System.Threading.Timer(obj => this.respawnVehicles = true, null, 0xbb8, -1);
        }

        public void saveBans()
        {
            PlayerPrefs.SetString("bans", this.bigAssStringWithBannedPlayerNamesAndSteamIDs);
        }

        private void scarePlayer(CommandArgs args)
        {
            Vector3 position = UserList.getUserFromName(args.ParametersAsString).position;
            for (int i = 0; i < 100; i++)
            {
                NetworkSounds.askSound("Sounds/Vehicles/horn", position, 50f, 1f, 20f);
            }
        }

        private void SetAnnounceDelay(CommandArgs args)
        {
            string str = args.Parameters[0];
            this.setAnnounceIntervalInSeconds(Convert.ToInt32(str));
        }

        public void setAnnounceIntervalInSeconds(int seconds)
        {
            this.announceIntervalInSeconds = seconds;
            this.announceTimer.Stop();
            this.announceTimer.Interval = seconds * 0x3e8;
            this.announceTimer.Start();
        }

        private void setHome(string steamID, Vector3 location)
        {
            if (this.playerHomes.ContainsKey(steamID))
            {
                string[] strArray = File.ReadAllLines("Unturned_Data/Managed/mods/AdminCommands/PlayerHomes.txt");
                File.Delete("Unturned_Data/Managed/mods/AdminCommands/PlayerHomes.txt");
                StreamWriter writer = new StreamWriter("Unturned_Data/Managed/mods/AdminCommands/PlayerHomes.txt", true);
                for (int i = 0; i < strArray.Length; i++)
                {
                    if (!strArray[i].StartsWith(steamID))
                    {
                        writer.WriteLine(strArray[i]);
                    }
                }
                writer.Close();
            }
            StreamWriter writer2 = new StreamWriter("Unturned_Data/Managed/mods/AdminCommands/PlayerHomes.txt", true);
            writer2.WriteLine(string.Concat(new object[] { steamID, ":", location.x, ",", location.y, ",", location.z }));
            writer2.Close();
            this.playerHomes[steamID] = location;
        }

        private void SetHome(CommandArgs args)
        {
            if (this.usePlayerHomes)
            {
                Vector3 position = NetworkUserList.getModelFromPlayer(args.sender.networkPlayer).transform.position;
                this.setHome(args.sender.steamid, position);
                Reference.Tell(args.sender.networkPlayer, "设置Home。");
            }
        }

        public void setItemResetIntervalInSeconds(int seconds)
        {
            this.itemsResetIntervalInSeconds = seconds;
            this.itemsTimer.Stop();
            this.itemsTimer.Interval = seconds * 0x3e8;
            this.itemsTimer.Start();
        }

        private void SetItemsDelay(CommandArgs args)
        {
            string str = args.Parameters[0];
            this.setItemResetIntervalInSeconds(Convert.ToInt32(str));
        }

        private void ShowAdminCommands(CommandArgs args)
        {
            string text = " /ban, /kick, /repeat, /reason, /resetitems, /repairvehicles, /refuelvehicles";
            string str2 = " /resetzombies, /killzombies, /kill, /setitemsdelay, /enablewhitelist";
            string str3 = " /disablewhitelist, /whitelist add & remove, /unban, /reloadCommands, ";
            string str4 = " /tptome <playername>, /promote, /online, /heal, /tp, /tpto <x> <y> <z>";
            string str5 = " /i <itemid> <amount>, /car, /kit /sethome, /home  (if enabled)";
            Reference.Tell(args.sender.networkPlayer, text);
            Reference.Tell(args.sender.networkPlayer, str2);
            Reference.Tell(args.sender.networkPlayer, str3);
            Reference.Tell(args.sender.networkPlayer, str4);
            Reference.Tell(args.sender.networkPlayer, str5);
        }

        private void SirensOff(CommandArgs args)
        {
            Vehicle[] vehicleArray = UnityEngine.Object.FindObjectsOfType(typeof(Vehicle)) as Vehicle[];
            foreach (Vehicle vehicle in vehicleArray)
            {
                vehicle.networkView.RPC("tellSirens", RPCMode.All, new object[] { false });
            }
        }

        private void SirensOn(CommandArgs args)
        {
            Vehicle[] vehicleArray = UnityEngine.Object.FindObjectsOfType(typeof(Vehicle)) as Vehicle[];
            foreach (Vehicle vehicle in vehicleArray)
            {
                vehicle.networkView.RPC("tellSirens", RPCMode.All, new object[] { true });
            }
        }

        private void SpawnItem(CommandArgs args)
        {
            int num = Convert.ToInt32(args.Parameters[0]);
            int num2 = 1;
            if (args.Parameters.Count == 2)
            {
                num2 = Convert.ToInt32(args.Parameters[1]);
            }
            Vector3 position = args.sender.position;
            for (int i = 0; i < num2; i++)
            {
                SpawnItems.spawnItem(num, 1, position);
            }
        }

        private void SpawnKit(CommandArgs args)
        {
            int[] numArray = new int[] { 
                0x7d4, 0x1b60, 0x2ee0, 0x232c, 0x2711, 0x2afb, 0x465e, 0x465e, 0x465e, 0x465e, 0x465e, 0x465e, 0x465e, 0xfb1, 0x1399, 11, 
                0x32c8, 0x32c8, 0x36c6, 0x36c6, 0x1f4f, 0x1f4d, 0xbba
             };
            Vector3 position = args.sender.position;
            foreach (int num in numArray)
            {
                SpawnItems.spawnItem(num, 1, position);
            }
        }

        public void Start()
        {
            Command command = new Command(0, new CommandDelegate(this.Online), new string[] { "online" })
            {
                description = "显示当前在线玩家数量"
            };
            CommandList.add(command);
            Command command2 = new Command(0, new CommandDelegate(this.Time), new string[] { "time" })
            {
                description = "显示游戏内时间"
            };
            CommandList.add(command2);
            Command command3 = new Command(0, new CommandDelegate(this.SetHome), new string[] { "sethome" })
            {
                description = "设置你的家（需要在配置文档中启用）"
            };
            CommandList.add(command3);
            Command command4 = new Command(0, new CommandDelegate(this.Home), new string[] { "home" })
            {
                description = "传送到你的家（需要在配置文档中启用）"
            };
            CommandList.add(command4);
            Command command5 = new Command(6, new CommandDelegate(this.Announce), new string[] { "repeat", "announce", "ann" })
            {
                description = "在服务器上发送绿字公告"
            };
            CommandList.add(command5);
            Command command6 = new Command(8, new CommandDelegate(this.Ban), new string[] { "ban" })
            {
                description = "Ban一个玩家，需要输入确认理由：/reason"
            };
            CommandList.add(command6);
            Command command7 = new Command(8, new CommandDelegate(this.ReasonForBan), new string[] { "reason", "r" })
            {
                description = "玩家被Ban时需要输入的理由"
            };
            CommandList.add(command7);
            Command command8 = new Command(7, new CommandDelegate(this.ResetItems), new string[] { "resetitems" })
            {
                description = "刷新全地图所有的物品"
            };
            CommandList.add(command8);
            Command command9 = new Command(7, new CommandDelegate(this.RepairVehicles), new string[] { "repairvehicles" })
            {
                description = "维修全部车辆"
            };
            CommandList.add(command9);
            Command command10 = new Command(7, new CommandDelegate(this.RefuelVehicles), new string[] { "refuelvehicles" })
            {
                description = "给全部车辆加满油"
            };
            CommandList.add(command10);
            Command command11 = new Command(7, new CommandDelegate(this.SirensOn), new string[] { "sirens" })
            {
                description = "开启所有车辆的喇叭"
            };
            CommandList.add(command11);
            Command command12 = new Command(7, new CommandDelegate(this.SirensOff), new string[] { "sirensoff" })
            {
                description = "禁止所有车辆的喇叭"
            };
            CommandList.add(command12);
            Command command13 = new Command(7, new CommandDelegate(this.ResetZombies), new string[] { "resetzombies" })
            {
                description = "重生并刷新所有僵尸"
            };
            CommandList.add(command13);
            Command command14 = new Command(7, new CommandDelegate(this.Killzombies), new string[] { "killzombies" })
            {
                description = "击杀所有僵尸"
            };
            CommandList.add(command14);
            Command command15 = new Command(7, new CommandDelegate(this.ReloadBans), new string[] { "reloadbans" })
            {
                description = "从注册表中载入被BAN玩家"
            };
            CommandList.add(command15);
            Command command16 = new Command(7, new CommandDelegate(this.SetItemsDelay), new string[] { "setitemsdelay" })
            {
                description = "设置物品刷新时间，以秒为单位。"
            };
            CommandList.add(command16);
            Command command17 = new Command(7, new CommandDelegate(this.SetAnnounceDelay), new string[] { "setannouncedelay" })
            {
                description = "设置公告时间，以秒为单位。"
            };
            CommandList.add(command17);
            Command command18 = new Command(8, new CommandDelegate(this.EnableWhitelist), new string[] { "enablewhitelist" })
            {
                description = "启用白名单"
            };
            CommandList.add(command18);
            Command command19 = new Command(8, new CommandDelegate(this.DisableWhitelist), new string[] { "disablewhitelist" })
            {
                description = "禁用白名单"
            };
            CommandList.add(command19);
            Command command20 = new Command(6, new CommandDelegate(this.Whitelist), new string[] { "whitelist" })
            {
                description = "从白名单上添加或移除一个玩家"
            };
            CommandList.add(command20);
            Command command21 = new Command(6, new CommandDelegate(this.UnBan), new string[] { "unban" })
            {
                description = "解BAN一个玩家"
            };
            CommandList.add(command21);
            Command command22 = new Command(6, new CommandDelegate(this.TeleportToPlayer), new string[] { "tp" })
            {
                description = "传送至一个玩家身上"
            };
            CommandList.add(command22);
            Command command23 = new Command(8, new CommandDelegate(this.TeleportToMe), new string[] { "tptome" })
            {
                description = "拉过来一个玩家"
            };
            CommandList.add(command23);
            Command command24 = new Command(6, new CommandDelegate(this.TeleportToCoords), new string[] { "tpto" })
            {
                description = "传送到坐标 x y z（y是高度）"
            };
            CommandList.add(command24);
            Command command25 = new Command(10, new CommandDelegate(this.TeleportAll), new string[] { "tpall" })
            {
                description = "拉过来所有玩家"
            };
            CommandList.add(command25);
            CommandList.add(new Command(8, new CommandDelegate(this.Kill), new string[] { "kill" }));
            CommandList.add(new Command(8, new CommandDelegate(this.Heal), new string[] { "heal" }));
            Command command26 = new Command(6, new CommandDelegate(this.TeleportCar), new string[] { "car" })
            {
                description = "拉过来一辆随机或者具体的车辆"
            };
            CommandList.add(command26);
            Command command27 = new Command(8, new CommandDelegate(this.SpawnItem), new string[] { "i" })
            {
                description = "刷物品"
            };
            CommandList.add(command27);
            CommandList.add(new Command(8, new CommandDelegate(this.SpawnKit), new string[] { "kit" }));
            Command command28 = new Command(7, new CommandDelegate(this.Kick), new string[] { "kick" })
            {
                description = "踢出一个玩家"
            };
            CommandList.add(command28);
            Command command29 = new Command(8, new CommandDelegate(this.GodMode), new string[] { "god" })
            {
                description = "无敌"
            };
            CommandList.add(command29);
            Command command30 = new Command(8, new CommandDelegate(this.FreezePlayer), new string[] { "freeze" })
            {
                description = "封冻一个玩家使其无法移动"
            };
            CommandList.add(command30);
            CommandList.add(new Command(8, new CommandDelegate(this.UnFreezePlayer), new string[] { "unfreeze" }));
            Command command31 = new Command(8, new CommandDelegate(this.UnFreezeAll), new string[] { "unfreezeall" })
            {
                description = "解冻所有玩家"
            };
            CommandList.add(command31);
            Command command32 = new Command(8, new CommandDelegate(this.RespawnVehicles), new string[] { "respawnvehicles" })
            {
                description = "刷新所有车辆"
            };
            CommandList.add(command32);
            Command command33 = new Command(8, new CommandDelegate(this.Vanish), new string[] { "vanish" })
            {
                description = "切换隐形"
            };
            CommandList.add(command33);
            Command command34 = new Command(8, new CommandDelegate(this.lag), new string[] { "lag" })
            {
                description = "阻止与所有玩家的通信服务"
            };
            CommandList.add(command34);
            CommandList.add(new Command(8, new CommandDelegate(this.unlag), new string[] { "unlag" }));
            CommandList.add(new Command(8, new CommandDelegate(this.scarePlayer), new string[] { "scare" }));
            Command command35 = new Command(7, new CommandDelegate(this.MaxSkills), new string[] { "maxskills" })
            {
                description = "给自己10000经验"
            };
            CommandList.add(command35);
            this.ReadConfigs();
        }

        private void TeleportAll(CommandArgs args)
        {
            Vector3 position = args.sender.position;
            Quaternion rotation = args.sender.player.gameObject.transform.rotation;
            foreach (BetterNetworkUser user in UserList.users)
            {
                this.teleportUserTo(user, position, rotation);
            }
        }

        private void TeleportCar(CommandArgs args)
        {
            Vector3 position = args.sender.position;
            Quaternion rotation = args.sender.rotation;
            Vector3 newPos = new Vector3(position[0] + 5f, position[1] + 50f, position[2]);
            if (args.Parameters.Count == 0)
            {
                Vehicle[] vehicleArray = UnityEngine.Object.FindObjectsOfType(typeof(Vehicle)) as Vehicle[];
                int index = UnityEngine.Random.Range(0, vehicleArray.Length);
                Vehicle vehicle = vehicleArray[index];
                vehicle.transform.position = newPos;
            }
            else
            {
                string cartype = args.Parameters[0];
                if (!cartype.Contains("_"))
                {
                    cartype = cartype + "_0";
                }
                GameObject obj2 = (GameObject)typeof(SpawnVehicles).GetFields()[0].GetValue(null);
                try
                {
                    if (obj2.transform.FindChild("models").childCount >= (Loot.getCars() - 1))
                    {
                        int num2 = UnityEngine.Random.Range(0, Loot.getCars());
                        Transform child = obj2.transform.FindChild("models").GetChild(num2);
                        Network.RemoveRPCs(child.networkView.viewID);
                        Network.Destroy(child.networkView.viewID);
                    }
                }
                catch
                {
                }
                System.Threading.Timer timer = new System.Threading.Timer(delegate(object obj)
                {
                    SpawnVehicles.create(cartype, 100, 100, newPos, rotation * Quaternion.Euler(-90f, 0f, 0f), new Color(UnityEngine.Random.Range((float)0f, (float)1f), UnityEngine.Random.Range((float)0f, (float)1f), UnityEngine.Random.Range((float)0f, (float)1f)));
                    SpawnVehicles.save();
                }, null, 400, -1);
                Reference.Tell(args.sender.networkPlayer, "Creating " + cartype);
            }
        }

        private void TeleportToCoords(CommandArgs args)
        {
            float x = float.Parse(args.Parameters[0]);
            float y = float.Parse(args.Parameters[1]);
            float z = float.Parse(args.Parameters[2]);
            this.teleportUserTo(args.sender, new Vector3(x, y, z));
        }

        private void TeleportToMe(CommandArgs args)
        {
            BetterNetworkUser user;
            string parametersAsString = args.ParametersAsString;
            int result = 0;
            if ((parametersAsString.Length < 3) && int.TryParse(parametersAsString, out result))
            {
                user = UserList.users[result];
            }
            else
            {
                user = UserList.getUserFromName(parametersAsString);
            }
            this.teleportUserTo(user, args.sender.position, args.sender.rotation);
        }

        private void TeleportToPlayer(CommandArgs args)
        {
            BetterNetworkUser user;
            string parametersAsString = args.ParametersAsString;
            int result = 0;
            if ((parametersAsString.Length < 3) && int.TryParse(parametersAsString, out result))
            {
                user = UserList.users[result];
            }
            else
            {
                user = UserList.getUserFromName(parametersAsString);
            }
            if (user != null)
            {
                this.teleportUserTo(args.sender, user.position, user.rotation);
            }
        }

        private void teleportUserTo(BetterNetworkUser user, Vector3 target)
        {
            user.position = target;
            user.player.gameObject.GetComponent<Life>().networkView.RPC("tellStatePosition", RPCMode.All, new object[] { target, user.rotation });
            user.player.gameObject.GetComponent<NetworkInterpolation>().tellStatePosition_Pizza(target, user.rotation);
            Network.SetReceivingEnabled(user.networkPlayer, 0, false);
            System.Threading.Timer timer = new System.Threading.Timer(obj => Network.SetReceivingEnabled(user.networkPlayer, 0, true), null, 0x7d0, -1);
        }

        private void teleportUserTo(BetterNetworkUser user, Vector3 targetposition, Quaternion targetrotation)
        {
            user.position = targetposition;
            user.player.gameObject.GetComponent<Life>().networkView.RPC("tellStatePosition", RPCMode.All, new object[] { targetposition, targetrotation });
            user.player.gameObject.GetComponent<NetworkInterpolation>().tellStatePosition_Pizza(targetposition, targetrotation);
            Network.SetReceivingEnabled(user.networkPlayer, 0, false);
            System.Threading.Timer timer = new System.Threading.Timer(obj => Network.SetReceivingEnabled(user.networkPlayer, 0, true), null, 0x7d0, -1);
        }

        private void Time(CommandArgs args)
        {
            NetworkChat.sendAlert("Time: " + Sun.getTime());
        }

        public bool unban(string name)
        {
            this.loadBans();
            string bigAssStringWithBannedPlayerNamesAndSteamIDs = this.bigAssStringWithBannedPlayerNamesAndSteamIDs;
            if (bigAssStringWithBannedPlayerNamesAndSteamIDs.Contains(name))
            {
                int index = bigAssStringWithBannedPlayerNamesAndSteamIDs.IndexOf(name);
                int num2 = ((name.Length + 1) + 0x11) + 2;
                string str2 = bigAssStringWithBannedPlayerNamesAndSteamIDs.Substring(0, index);
                string str3 = bigAssStringWithBannedPlayerNamesAndSteamIDs.Substring(index + num2);
                bigAssStringWithBannedPlayerNamesAndSteamIDs = str2 + str3;
            }
            else
            {
                return false;
            }
            this.bigAssStringWithBannedPlayerNamesAndSteamIDs = bigAssStringWithBannedPlayerNamesAndSteamIDs;
            this.saveBans();
            NetworkBans.load();
            return true;
        }

        private void UnBan(CommandArgs args)
        {
            string parametersAsString = args.ParametersAsString;
            if (this.unban(parametersAsString))
            {
                Reference.Tell(args.sender.networkPlayer, parametersAsString + " 已被解Ban。");
            }
            else
            {
                Reference.Tell(args.sender.networkPlayer, "被Ban玩家中找不到玩家<" + parametersAsString + ">");
            }
        }

        private void UnFreezeAll(CommandArgs args)
        {
            this.frozenPlayers.Clear();
        }

        private void UnFreezePlayer(CommandArgs args)
        {
            BetterNetworkUser user = UserList.getUserFromName(args.ParametersAsString);
            if (user != null)
            {
                this.frozenPlayers.Remove(user.steamid);
            }
            Reference.Tell(args.sender.networkPlayer, "解冻玩家<" + user.name + ">");
        }

        private void unlag(CommandArgs args)
        {
            BetterNetworkUser user = UserList.getUserFromName(args.ParametersAsString);
            Network.SetReceivingEnabled(user.networkPlayer, 0, true);
            Reference.Tell(args.sender.networkPlayer, "你已不再人为LAG" + user.name);
        }

        public void Update()
        {
            BetterNetworkUser user;
            this.kickNonWhitelistedPlayers();
            if (this.respawnVehicles)
            {
                this.respawnVehicles = false;
                UnityEngine.Object.FindObjectOfType<SpawnVehicles>().onReady();
            }
            if (this.frozenPlayers.Count > 0)
            {
                foreach (KeyValuePair<string, Vector3> pair in this.frozenPlayers)
                {
                    user = UserList.getUserFromSteamID(pair.Key);
                    if (user != null)
                    {
                        user.player.transform.position = pair.Value;
                        user.player.networkView.RPC("tellStatePosition", user.player.networkView.owner, new object[] { pair.Value, user.player.transform.rotation });
                    }
                }
            }
            if (this.vanishedPlayers.Count > 0)
            {
                foreach (KeyValuePair<string, Vector3> pair in this.vanishedPlayers)
                {
                    user = UserList.getUserFromSteamID(pair.Key);
                    if (user != null)
                    {
                        foreach (NetworkPlayer player in Network.connections)
                        {
                            if ((Network.player != player) && (player != user.networkPlayer))
                            {
                                user.player.networkView.RPC("tellStatePosition", player, new object[] { new Vector3(0f, 0f, 0f), user.rotation });
                            }
                        }
                    }
                }
            }
        }

        private void Vanish(CommandArgs args)
        {
            try
            {
                this.vanishedPlayers.Add(args.sender.steamid, new Vector3(0f, 0f, 0f));
                Reference.Tell(args.sender.networkPlayer, "你已隐形！:D");
            }
            catch
            {
                this.vanishedPlayers.Remove(args.sender.steamid);
                Reference.Tell(args.sender.networkPlayer, "你已解除隐形！");
            }
        }

        private void Whitelist(CommandArgs args)
        {
            string parametersAsString;
            string steamid;
            StreamWriter writer;
            if (args.Parameters[0].Equals("add"))
            {
                args.Parameters.RemoveAt(0);
                parametersAsString = args.ParametersAsString;
                steamid = "";
                try
                {
                    steamid = UserList.getUserFromName(parametersAsString).steamid;
                    parametersAsString = UserList.getUserFromName(parametersAsString).name;
                }
                catch
                {
                    if (parametersAsString.StartsWith("765611"))
                    {
                        steamid = parametersAsString;
                    }
                    else
                    {
                        Reference.Tell(args.sender.networkPlayer, "那个玩家已不在线或者你提供了一个错误的STEAMID");
                        return;
                    }
                }
                writer = new StreamWriter("Unturned_Data/Managed/mods/AdminCommands/UnturnedWhitelist.txt", true);
                writer.WriteLine("");
                writer.WriteLine(steamid);
                writer.Close();
                this.WhitelistedSteamIDs.Add(steamid);
                Reference.Tell(args.sender.networkPlayer, "已添加一个STEAMID " + parametersAsString + " (" + steamid + ")" + "到白名单");
            }
            else if ((args.Parameters[0].ToLower().Equals("remove") || args.Parameters[0].ToLower().Equals("del")) || args.Parameters[0].ToLower().Equals("rem"))
            {
                args.Parameters.RemoveAt(0);
                parametersAsString = args.ParametersAsString;
                steamid = "";
                try
                {
                    steamid = UserList.getUserFromName(parametersAsString).steamid;
                    parametersAsString = UserList.getUserFromName(parametersAsString).name;
                }
                catch
                {
                    if (parametersAsString.StartsWith("765611"))
                    {
                        steamid = parametersAsString;
                    }
                    else
                    {
                        Reference.Tell(args.sender.networkPlayer, "那个玩家已不在线或者你提供了一个错误的STEAMID");
                        return;
                    }
                }
                this.WhitelistedSteamIDs.Remove(steamid);
                File.Delete("Unturned_Data/Managed/mods/AdminCommands/UnturnedWhitelist.txt");
                writer = new StreamWriter("Unturned_Data/Managed/mods/AdminCommands/UnturnedWhitelist.txt", true);
                for (int i = 0; i < this.WhitelistedSteamIDs.Count; i++)
                {
                    writer.WriteLine(this.WhitelistedSteamIDs[i]);
                }
                writer.Close();
                Reference.Tell(args.sender.networkPlayer, "从白名单中移除一个STEAMID " + parametersAsString + " (" + steamid + ")");
            }
        }
    }
}
